package com.qf.work.service.impl;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.qf.work.entity.Workorder;
import com.qf.work.mapper.WorkorderMapper;
import com.qf.work.service.WorkorderService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @Author songfei
 * @Date 2021/10/7 15:13
 * @Version 1.0
 */
@Service
public class WorkorderServiceImpl implements WorkorderService {
    @Autowired
    private WorkorderMapper workorderMapper;

    @Override
    public void insert(Workorder workorder) {
        int i = workorderMapper.insertSelective(workorder);
        if(i!=1){
            System.out.println("添加工单信息失败");
            throw new RuntimeException("添加工单信息失败");
        }
    }

    @Override
    public PageInfo<Workorder> findByProjectIdAndPage(Integer page, Integer rows, Integer projectId) {
        //1.分页
        PageHelper.startPage(page,rows);
        //2.查询
        List<Workorder> workorderList = workorderMapper.findByDistrictId(projectId);
        //3.分装PageInfo
        PageInfo<Workorder> pageInfo = new PageInfo<>(workorderList);
        //4.返回
        return pageInfo;

    }
}
